package com.love.marriage.carouselBannerInfo.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.love.marriage.carouselBannerInfo.service.CarouselBannerInfoService;
import com.love.marriage.carouselBannerInfo.vo.CarouselBannerInfoVo;
import com.love.marriage.carouselBannerInfo.vo.ResultCarouselBannerInfoVo;
import com.love.marriage.carouselBannerInfo.vo.ResultCarouselBannerInfoVoList;
import com.love.marriage.carouselBannerInfo.vo.ResultCarouselBannerInfoVoPage;
import com.love.marriage.common.interfaces.avoid.AvoidRepeatableCommit;
import com.love.marriage.common.validator.Update;
import com.love.marriage.common.vo.Result;
import com.love.marriage.common.vo.ResultBoolean;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * description:  展示轮播图表restApi
 * author:       mybatisPlus
 * createDate:   2024-10-20 10:10:51
 * version:      1.0.0
 */
@ApiSort(105)
@Tag(name = "展示轮播图表相关接口", description = "展示轮播图表相关接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("/carousel-banner-info")
public class CarouselBannerInfoController {

    private final CarouselBannerInfoService carouselBannerInfoService;

    @ApiOperationSupport(order = 10, author = "mybatisPlus")
    @Operation(summary = "获取展示轮播图表分页", description = "获取展示轮播图表分页")
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(mediaType = "application/json",
                    schema = @Schema(implementation = ResultCarouselBannerInfoVoPage.class
                    )))
    @PostMapping(value = "/page")
    @Parameters({
            @Parameter(name = "pageNum", description = "页码", required = false),
            @Parameter(name = "pageSize", description = "每页大小", required = false)
    })
    @Tag(name = "展示轮播图表相关接口", description = "展示轮播图表相关接口")
    public Result<Page<CarouselBannerInfoVo>> getPage(@RequestParam(value = "pageNum", required = false) Long pageNum,
                                                      @RequestParam(value = "pageSize", required = false) Long pageSize,
                                                      @RequestBody(required = false) CarouselBannerInfoVo carouselBannerInfoVo) {
        return Result.success(carouselBannerInfoService.getPage(pageNum, pageSize, carouselBannerInfoVo));
    }

    @ApiOperationSupport(order = 15, author = "mybatisPlus")
    @Operation(summary = "轮播图列表", description = "轮播图列表")
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(mediaType = "application/json",
                    schema = @Schema(implementation = ResultCarouselBannerInfoVoList.class
                    )))
    @PostMapping(value = "/list")
    @Tag(name = "公共", description = "公共接口")
    public Result<List<CarouselBannerInfoVo>> list(@RequestBody(required = false) CarouselBannerInfoVo carouselBannerInfoVo) {
        return Result.success(carouselBannerInfoService.list(carouselBannerInfoVo));
    }

    @ApiOperationSupport(order = 20, author = "mybatisPlus")
    @Operation(summary = "获取展示轮播图表详情", description = "获取展示轮播图表详情")
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(mediaType = "application/json",
                    schema = @Schema(implementation = ResultCarouselBannerInfoVo.class
                    )))
    @Parameters({
            @Parameter(name = "id", description = "id", required = true, schema = @Schema(implementation = Long.class, type = "Long", example = "1"))
    })
    @GetMapping
    public Result<CarouselBannerInfoVo> query(@RequestParam(value = "id") Long id) {
        return Result.success(carouselBannerInfoService.queryCarouselBannerInfo(id));
    }

    @AvoidRepeatableCommit
    @ApiOperationSupport(order = 30, author = "mybatisPlus")
    @Operation(summary = "新增展示轮播图表", description = "新增展示轮播图表")
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(schema = @Schema(implementation = ResultCarouselBannerInfoVo.class)))
    @PostMapping(value = "/addBanner")
    public Result<CarouselBannerInfoVo> add(@RequestParam(value = "title", required = false) String title,
                                            @RequestPart(value = "file") MultipartFile file) throws Exception {
        return Result.success(carouselBannerInfoService.addCarouselBannerInfo(title, file));
    }

    @ApiOperationSupport(order = 40, author = "mybatisPlus")
    @Operation(summary = "新增展示轮播图表", description = "新增展示轮播图表",
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    description = "查询条件",
                    required = false,
                    content = @Content(schema = @Schema(implementation = CarouselBannerInfoVo.class))
            ))
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(schema = @Schema(implementation = ResultCarouselBannerInfoVo.class)))
    @PostMapping
    public Result<CarouselBannerInfoVo> add(@RequestBody CarouselBannerInfoVo carouselBannerInfoVo) throws Exception {
        return Result.success(carouselBannerInfoService.addCarouselBannerInfo(carouselBannerInfoVo));
    }

    @ApiOperationSupport(order = 40, author = "mybatisPlus")
    @Operation(summary = "修改展示轮播图表", description = "修改展示轮播图表",
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    description = "查询条件",
                    required = false,
                    content = @Content(schema = @Schema(implementation = CarouselBannerInfoVo.class))
            ))
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(schema = @Schema(implementation = ResultCarouselBannerInfoVo.class)))
    @PutMapping
    public Result<CarouselBannerInfoVo> update(@Validated({Update.class}) @RequestBody CarouselBannerInfoVo carouselBannerInfoVo) {
        return Result.success(carouselBannerInfoService.updateCarouselBannerInfo(carouselBannerInfoVo));
    }

    @ApiOperationSupport(order = 50, author = "mybatisPlus")
    @Operation(summary = "刪除展示轮播图表", description = "刪除展示轮播图表")
    @Parameters({
            @Parameter(name = "ids", description = "ids,用，分割", required = true, schema = @Schema(implementation = String.class, type = "String", example = "1,2"))
    })
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(schema = @Schema(implementation = ResultBoolean.class)))
    @DeleteMapping
    public Result<Boolean> delete(@RequestParam("ids") String ids) {
        return Result.success(carouselBannerInfoService.deleteCarouselBannerInfo(ids));
    }
}
